Skip to content

feat(Experiments): Get experiment flags, and track events and exposures - #83

Merged
gagantrivedi merged 6 commits into
mainfrom
openhands/sdk-spec-v0.7.1
Nov 10, 2026
Merged

gagantrivedi merged 6 commits into
mainfrom
openhands/sdk-spec-v0.7.1

Conversation

@flagsmithsmith

@flagsmithsmith flagsmithsmith Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Lets Rust applications run experiments with Flagsmith. An application can get an identity's experiment flag, which records which variant the identity was exposed to. It can also send tracking events, such as conversions, to Flagsmith's events API. This implements SDK spec v0.7.1, and its spec run now includes the events scenarios.

Changes

  • Events can be enabled on the client (enable_events). Events are buffered and sent to Flagsmith's events API in batches: on a timer, when the buffer fills, on flush_events, and when the client is dropped. The events API URL, flush interval and buffer size can be configured. Offline clients send no events.
  • get_experiment_flag returns an identity's flag, and requires an identifier. When the identity is enrolled in a running experiment, it also records a $flag_exposure event for the variant served, with the identity's traits.
  • track_event records an application event, with an optional identity, value and metadata. Names starting with $ are reserved.
  • track_exposure_event records an exposure for a variant evaluated elsewhere. It requires an identity.
  • Flags from remote identity evaluation carry the variant served and the running experiment.
  • Updates the SDK spec to v0.7.1, from Renovate's deps: update dependency flagsmith/sdk-spec to v0.9.0 #82, and runs its core, events and local-evaluation scenarios. Empty string flag values, new in v0.7.1, already worked.

Contributes to Flagsmith/sdk-spec#13

Review effort: 3/5

renovate Bot and others added 2 commits November 5, 2026 17:37
Its entry in Flagsmith/sdk-spec's compatibility matrix at v0.7.1: `core or events or local-evaluation`.
@flagsmithsmith flagsmithsmith Bot added the sdk-spec Bumps of the Flagsmith SDK behavioural spec label Nov 5, 2026
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 227e54e7-2c39-47f3-b8f3-d43871d7cb7f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codspeed

codspeed Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 15 skipped benchmarks1


Comparing openhands/sdk-spec-v0.7.1 (cb52492) with main (de1d8e8)

Open in CodSpeed

Footnotes

  1. 15 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Implements the experimentation features the SDK spec's `events`
scenarios require, run from SDK spec v0.7.1:

- `enable_events` starts an event processor that buffers events and
  sends them to Flagsmith's events API in batches.
- `get_experiment_flag` resolves a flag for an identity and records a
  `$flag_exposure` when the identity is enrolled in a running experiment.
- `track_event` and `track_exposure_event` record events directly.
- `Flag` exposes the `variant` and `experiment` served by remote
  identity evaluation.

Re-applied from f28b98d on top of
flag dependency evaluation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@flagsmithsmith

flagsmithsmith Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

The SDK spec was failing because v0.7.1 runs this SDK's events scenarios: experiment flags, tracking events and exposure events. This SDK had no steps for them. The SDK side was already written in f28b98d, so this re-applies it on top of flag dependency evaluation as 0a6f487.

Changes

  • The client can be configured to send events to Flagsmith's events API (enable_events, events_api_url, flush interval and buffer size). Events are buffered and sent in batches.
  • get_experiment_flag returns an identity's flag. When the identity is in a running experiment, it also records a $flag_exposure event for the variant served.
  • track_event and track_exposure_event record events directly. Names starting with $ are reserved, and an exposure needs an identifier.
  • Flags from remote identity evaluation expose variant and experiment.
  • The spec steps call these SDK methods.

The re-application had two conflicts, in sdk-spec/steps.rs and tests/integration_test.rs. Both sides of each were additions, so I kept both. The commit also needed a HashMap import, which main had removed in the meantime. v0.7.1 also adds empty-string flag values (""). The SDK already handled those, and they passed in the previous CI run.

Checked locally: cargo fmt --check, cargo test --all-features --workspace (34 unit and 37 integration tests), cargo +1.86.0 check, and the v0.7.1 spec for core or events or local-evaluation against its compose stack (9 of 9 passed).

Review effort: 3/5

@flagsmithsmith
flagsmithsmith Bot marked this pull request as ready for review November 5, 2026 21:02
@flagsmithsmith
flagsmithsmith Bot requested a review from a team as a code owner November 5, 2026 21:02
@flagsmithsmith
flagsmithsmith Bot requested review from khvn26 and removed request for a team November 5, 2026 21:02
@flagsmithsmith flagsmithsmith Bot changed the title feat: Implement SDK spec v0.7.1 feat: Support getExperimentFlag, trackEvent and trackExposure methods Nov 6, 2026
gagantrivedi

This comment was marked as duplicate.

@gagantrivedi gagantrivedi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the pr description and title based on what's implemented in the pull request

@flagsmithsmith flagsmithsmith Bot changed the title feat: Support getExperimentFlag, trackEvent and trackExposure methods feat(Experiments): Get experiment flags, and track events and exposures Nov 10, 2026
@flagsmithsmith

Copy link
Copy Markdown
Contributor Author

Update the pr description and title based on what's implemented in the pull request

update the pr description and title based on what's implemented in the pull request

Both are done. No code changed, so there is no new commit.

  • The old title, feat: Support `getExperimentFlag`, `trackEvent` and `trackExposure` methods, named JS methods that this SDK doesn't have. The new title is feat(Experiments): Get experiment flags, and track events and exposures.

  • The old description only linked sdk-spec#13. The new one lists what this pull request adds:

    • enabling events, and how they're batched and sent
    • get_experiment_flag, track_event and track_exposure_event
    • the variant and experiment on flags
    • the spec bump to v0.7.1

    It still links Support getExperimentFlag, trackEvent and trackExposure methods sdk-spec#13.

Comment thread src/flagsmith/mod.rs Resolved
Comment thread src/flagsmith/mod.rs Resolved
An offline client still started the event processor when events were
enabled, so tracking and exposure events reached the events API. In
offline mode the processor is no longer started, and experiment flags
and event tracking return an error that names offline mode, as the
Python SDK does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/flagsmith/mod.rs Resolved
flagsmithsmith Bot and others added 2 commits November 10, 2026 12:09
get_experiment_flag sent its exposure straight to the event processor,
skipping the identifier check of track_exposure_event, and requested
flags for an empty identity. It now returns an error before any request,
as track_exposure_event does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An exposure event requires an identifier, yet it was an optional field of
EventOptions, so a missing one was only caught at runtime. The identifier
is now an argument: required by track_exposure_event, and optional for
track_event, whose events need not be about an identity. EventOptions
keeps the optional value, traits and metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gagantrivedi
gagantrivedi merged commit 23b6a53 into main Nov 10, 2026
7 checks passed
gagantrivedi pushed a commit that referenced this pull request Nov 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[3.3.0](v3.2.0...v3.3.0)
(2026-11-10)


### Features

* **Experiments:** Get experiment flags, and track events and exposures
([#83](#83))
([23b6a53](23b6a53))


### Other

* Let Renovate keep updating spec bumps the webhook handler commits to
([#79](#79))
([de1d8e8](de1d8e8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk-spec Bumps of the Flagsmith SDK behavioural spec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants